import java.io.File;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.swing.filechooser.*;

public class ExampleFileFilter extends FileFilter  {
	private java.util.Hashtable<java.lang.String,ExampleFileFilter> filters = null;
	private String description = null;
	private String fullDescription = null;
	private boolean useExtensionsInDescription = true;


	public ExampleFileFilter() {
		this.filters = new java.util.Hashtable<java.lang.String,ExampleFileFilter>();
	}


	public ExampleFileFilter(String extension) {
		
	}


	public ExampleFileFilter(String extension,String description) {
		
		if (extension != null) {
addExtension(extension);
}
		if (description != null) {
setDescription(description);
}
	}


	public ExampleFileFilter(java.lang.String[] filters) {
		
	}


	public ExampleFileFilter(java.lang.String[] filters,String description) {
		
		for(int i = 0; i < filters.length; i++) {
addExtension(filters[i]);
}
		if (description != null) {
setDescription(description);
}
	}



	public String getExtension(File f) {
		if (f != null) {
		String filename = f.getName();
		int i = filename.lastIndexOf('.');
if (i > 0 && i < filename.length() - 1) {
return filename.substring(i + 1).toLowerCase();

}


}
		return null;
	}


	public void addExtension(String extension) {
		if (filters == null) {
filters = new java.util.Hashtable<java.lang.String,ExampleFileFilter>(5);

}
		filters.put(extension.toLowerCase(), this);
		fullDescription = null;
	}


	public void setDescription(String description) {
		this.description = description;
		fullDescription = null;
	}


	public void setExtensionListInDescription(boolean b) {
		useExtensionsInDescription = b;
		fullDescription = null;
	}


	public boolean isExtensionListInDescription( ) {
		return useExtensionsInDescription;
	}


	public boolean accept(File f) {
		if (f != null) {
if (f.isDirectory()) {
return true;

}
		String extension = getExtension(f);
if (extension != null && filters.get(getExtension(f)) != null) {
return true;

}


}
		return false;
	}


	public String getDescription( ) {
		if (fullDescription == null) {
if (description == null || isExtensionListInDescription()) {
fullDescription = description == null ? "(" : description + " (";
		Enumeration extensions = filters.keys();
if (extensions != null) {
fullDescription += "." + (String) extensions.nextElement();
while(extensions.hasMoreElements()) {
fullDescription += ", ." + (String) extensions.nextElement();
}

}
fullDescription += ")";

} else {
fullDescription = description;
}

}
		return fullDescription;
	}


}
